package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/9.
 */
@HttpInlet(Conn.INLET_GET_FREEWAY_ORDER)
public class GetFreeWayOrder extends JTAsyGet<GetFreeWayOrder.Info>{

    public String token = JTApplication.jtPreferences.readToken();

    public String obdId = JTApplication.jtPreferences.readOdbID();


//    public String token = "74PWI719WPA5GY23AURVFBMLOPSQ5Z";
//
//    public String obdId = "2";

    public GetFreeWayOrder(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.code = head.optString("code");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONObject state = body.optJSONObject("map");

        info.state = state.optString("isGsType");

        info.name = state.optString("nickname");

        info.plate = state.optString("plateNum");

        info.licensee = state.optString("carNum");

        JSONArray array = body.optJSONArray("egsOrderList");

        if(array != null){

            for (int i = 0 ; i < array.length() ; i++){

                JSONObject o = array.optJSONObject(i);

                Item item = new Item();

                item.id = o.optString("ORDER_NUM");

                item.start_time = o.optString("IN_TIME");

                item.end_time = o.optString("OUT_TIME");

                item.total_time = o.optString("ORDER_TIME");

                item.meilage = o.optString("MILEAGE");

                item.start_point = o.optString("IN_NAME");

                item.end_point = o.optString("OUT_NAME");

                item.station = o.optString("DETAIL_COUNT");

                item.money = o.optString("PRICE");

                item.benefit = o.optString("SALE ");

                info.freewayList.add(item);

            }

        }

        return info;
    }

    public static class Info{

        public String msg;

        public String code;

        public String state,name,licensee,plate;

        public List<Item> freewayList = new ArrayList<>();

    }

    public static class Item{

        public String id;

        public String start_time,end_time,total_time;

        public String meilage;

        public String start_point,end_point;

        public String station,money,benefit;

    }

}
